//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#if _MSC_VER > 1000
#pragma once
#endif

#ifndef __PSEUDOCENTRAL_H__
#define __PSEUDOCENTRAL_H__

#include <elasys_server.h>
#include <aura.h>

ECode PseudoCentral_Initialize();
void  PseudoCentral_Destroy();

class CPseudoCentral
{
public:
    STATIC ECode Process_Create(
            /* [in] */ ThreadPriorityRank priorityRank,
            /* [in] */ Int32 capacity,
            /* [in] */ WString name,
            /* [in] */ WString args,
            /* [out] */ ProcessId * pProcessId);

    STATIC ECode Process_Open(
            /* [in] */ WString name,
            /* [in] */ WString args,
            /* [in] */ ProcessId processId);

    STATIC ECode Process_Kill(
            /* [in] */ ProcessId processId,
            /* [in] */ ExitCode exitCode);

    STATIC ECode Process_Release(
            /* [in] */ ProcessId processId);

    STATIC ECode Process_GetStartInfo(
            /* [in] */ ProcessId processId,
            /* [out] */ WStringBuf * pName,
            /* [out] */ WStringBuf * pArgs);

    STATIC ECode Process_WaitForExit(
            /* [in] */ ProcessId processId,
            /* [in] */ Millisecond32 timeout,
            /* [out] */ WaitResult * pResult);

    STATIC ECode Process_IsAlive(
            /* [in] */ ProcessId processId,
            /* [out] */ Boolean * pIsAlive);

    STATIC ECode Process_GetExitCode(
            /* [in] */ ProcessId processId,
            /* [out] */ ExitCode * pExitCode);

    STATIC ECode Process_GetStartTime(
            /* [in] */ ProcessId processId,
            /* [out]*/ SystemTime * pTime);

    STATIC ECode Process_GetExitTime(
            /* [in] */ ProcessId processId,
            /* [out] */ SystemTime * pTime);

    STATIC ECode Process_GetProcessorTimes(
            /* [in]  */ ProcessId processId,
            /* [out] */ Millisecond32 * pUserTime,
            /* [out] */ Millisecond32 * pPrivilegedTime);

    STATIC ECode Process_TransferInfo(
            /* [in] */ ProcessId processId,
            /* [in] */ ExitCode exitCode,
            /* [in] */ Millisecond32 userTime,
            /* [in] */ Millisecond32 privilegedTime);


    STATIC ECode Thread_AddRef(
            /* [in] */ ThreadId threadId,
            /* [in] */ ProcessId hostPid);

    STATIC ECode Thread_Release(
            /* [in] */ ThreadId threadId);

    STATIC ECode Thread_GetQuitCode(
            /* [in] */ ThreadId threadId,
            /* [out] */ QuitCode * pQuitCode);

    STATIC ECode Thread_GetStartTime(
            /* [in] */ ThreadId threadId,
            /* [out] */ SystemTime * pTime);

    STATIC ECode Thread_GetQuitTime(
            /* [in] */ ThreadId threadId,
            /* [out] */ SystemTime * pTime);

    STATIC ECode Thread_GetName(
            /* [in] */ ThreadId threadId,
            /* [out] */ WStringBuf * pName);

    STATIC ECode Thread_TransferInfo(
            /* [in] */ ThreadId threadId,
            /* [in] */ QuitCode quitCode,
            /* [in] */ SystemTime startTime,
            /* [in] */ SystemTime quitTime,
            /* [in] */ WString name);


    STATIC ECode Enumerator_Create(
            /* [in] */ Int32 * pEnumeratorId);

    STATIC ECode Enumerator_Release(
            /* [in] */ Int32 enumeratorId);

    STATIC ECode Enumerator_GetCurrent(
            /* [in] */ Int32 enumeratorId,
            /* [out] */ ProcessId * pProcessId);

    STATIC ECode Enumerator_MoveNext(
            /* [in] */ Int32 enumeratorId,
            /* [out] */ Boolean * pbSucceeded);

    STATIC ECode Enumerator_Reset(
            /* [in] */ Int32 enumeratorId);


//  For CMutex:
    STATIC CARAPI CreateNamedMutex(
            /* [in] */ WString name,
            /* [out] */ Boolean * pbAlreadyExists,
            /* [out] */ oid_t * pOid);

//  For CEvent:
    STATIC CARAPI CreateNamedEvent(
            /* [in] */ WString name,
            /* [in] */ Boolean bManuualReset,
            /* [in] */ EventState initialState,
            /* [out] */ Boolean * pbAlreadyExisted,
            /* [out] */ oid_t * pOid);

    STATIC CARAPI TrywaitNamedEvent(
            /* [in] */ oid_t oid,
            /* [in] */ Millisecond32 msTimeOut,
            /* [out] */ WaitResult * pResult,
            /* [out] */ EventState * pState);

    STATIC CARAPI NotifyNamedEvent(
            /* [in] */ oid_t oid,
            /* [in] */ EventState state);

    STATIC CARAPI ClearNamedEvent(
            /* [in] */ oid_t oid);

// for CCondition;
    STATIC ECode Condition_Create(
            /* [in] */ WString name,
            /* [out] */ Boolean * pbAlreadyExisted,
            /* [out] */ oid_t * pOid);

    STATIC ECode Condition_Wait(
            /* [in] */ oid_t oid,
            /* [in] */ Millisecond32 msTimeOut,
            /* [out] */ WaitResult * pResult);

    STATIC ECode Condition_Pulse(
            /* [in] */ oid_t oid);

    STATIC ECode Condition_PulseAll(
            /* [in] */ oid_t oid);

// for sharedmemory:
    STATIC CARAPI CreateSharedMemory(
            /* [in] */ WString name,
            /* [in] */ MemorySize size,
            /* [in] */ Boolean bCommit,
            /* [out] */ Boolean * pbAlreadyExisted,
            /* [out] */ oid_t * pOid);

    STATIC CARAPI  AddRefNamedObject(
            /* [in] */ oid_t oid);

    STATIC CARAPI  ReleaseNamedObject(
            /* [in] */ oid_t oid);

// for service.
    STATIC CARAPI SrvcRegister(
            /* [in] */ PEMuid pClsId,
            /* [in] */ PEIID pIid,
            /* [in] */ UInt32 uIndex,
            /* [out] */ oid_t * pOid);

    STATIC CARAPI SrvcUnregister(
            /* [in] */ oid_t oid);

    STATIC CARAPI SrvcRegisterCommon(
            /* [in] */ WString srvName,
            /* [in] */ PEMuid pClsId,
            /* [in] */ PEIID pIid,
            /* [in] */ UInt32 uIndex,
            /* [out] */ oid_t * pOid);

    STATIC CARAPI SrvcUnregsiterCommon(
            /* [in] */ WString srvName);

    STATIC CARAPI SrvcResolveCommon(
            /* [in] */ WString srvName,
            /* [out] */ ProcessId * pProcessId,
            /* [out] */ ObjectType * pType,
            /* [out] */ oid_t * pOid,
            /* [out] */ EMuid * pClsId,
            /* [out] */ UInt32 * pUIndex);

    STATIC CARAPI AttachImportService(
            /* [in] */ oid_t oid);

    STATIC CARAPI DetachImportService(
            /* [in] */ oid_t oid);

    STATIC CARAPI SrvcGetChannelName(
            /* [in] */ oid_t oid,
            /* [out] */ WStringBuf * name);

    STATIC CARAPI SrvcRegisterService(
            /* [in] */ WString serviceName,
            /* [in] */ oid_t oid);

    STATIC CARAPI SrvcWaitService(
            /* [in] */ WString srvName,
            /* [in] */ Millisecond32 msTimeout,
            /* [out] */ WaitResult * pResult);
};

#endif // __PSEUDOCENTRAL_H__
